<!--
 * @Author: your name
 * @Date: 2022-04-19 14:11:50
 * @LastEditTime: 2022-04-20 09:14:09
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \2202\二阶段学习\week02\day05\src\消灭星星\随机出现星星.html
-->
<meta charset="UTF-8">
<style>
    html,body{
        background: black;
    }
</style>
<button>点击加星星</button>
<script>
    setInterval("createStar()",1000)
    function createStar(){
        var imgObj = document.createElement('img')
        imgObj.src = 'star.gif'
        var nowwidth = Math.floor(Math.random()*(80-50+1)+50)
        imgObj.style.width = nowwidth + 'px'
        var maxLeft = (window.innerWidth || document.documentElement.clientWidth) - nowwidth
        var maxTop = (window.innerWidth || document.documentElement.clientHeight) - nowwidth
        imgObj.style.position = 'absolute'
        imgObj.style.left = Math.floor(Math.random()*(maxLeft-0+1)+0) + 'px'
        imgObj.style.top = Math.floor(Math.random()*(maxTop-0+1)+0) + 'px'
        document.body.appendChild(imgObj)
    }
</script>